Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@alwatr/global-scope
Advanced tools
This TypeScript module provides a cross-platform alternative to `globalThis` named `globalScope`. This object works across different environments, including browsers (`window`), Node.js (`global`), and Web Workers (`self`).
This TypeScript module provides a cross-platform alternative to globalThis
named globalScope
. This object works across different environments, including browsers (window
), Node.js (global
), and Web Workers (self
).
import {globalScope} from '@alwatr/global-scope';
globalScope.alwatr = {
...globalScope.alwatr,
version: '1.0.0',
};
globalScope.setTimeout(() => {
console.log(globalScope.alwatr.version); // 1.0.0
}, 1_000);
The module also includes a polyfill for globalThis
to ensure compatibility across different JavaScript environments.
if (globalScope.globalThis !== globalScope) {
globalScope.globalThis = globalScope;
}
The module exports a sharedScope_
object. This object can be used to share state across different modules without making the data publicly accessible in the global scope.
For example, one module can set a property on sharedScope_
, and another module can read that property. This allows for data sharing between different parts of your application.
// module1.ts
import {sharedScope_} from '@alwatr/global-scope';
sharedScope_.foo = 'bar';
// module2.ts
import {sharedScope_} from '@alwatr/global-scope';
console.log(sharedScope_.foo); // 'bar'
The module includes a check for duplication of the global scope definition. If the global scope has already been defined, an error is thrown.
if (globalScope.__shared_scope_defined__ !== undefined) {
throw new Error('global_scope_module_duplicated');
}
globalScope.__shared_scope_defined__ = true;
This ensures that the global scope module is not accidentally included multiple times, which could lead to unexpected behavior from shared scope.
The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.
Contributions are welcome! Please read our contribution guidelines before submitting a pull request.
This project is licensed under the AGPL-3.0 License.
FAQs
This TypeScript module provides a cross-platform alternative to `globalThis` named `globalScope`. This object works across different environments, including browsers (`window`), Node.js (`global`), and Web Workers (`self`).
The npm package @alwatr/global-scope receives a total of 140 weekly downloads. As such, @alwatr/global-scope popularity was classified as not popular.
We found that @alwatr/global-scope demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.